//package com.wb.config;
//
//import com.github.kristofa.brave.Brave;
//import com.github.kristofa.brave.Brave.Builder;
//import com.github.kristofa.brave.EmptySpanCollectorMetricsHandler;
//import com.github.kristofa.brave.Sampler;
//import com.github.kristofa.brave.SpanCollector;
//import com.github.kristofa.brave.http.DefaultSpanNameProvider;
//import com.github.kristofa.brave.http.HttpSpanCollector;
//import com.github.kristofa.brave.httpclient.BraveHttpRequestInterceptor;
//import com.github.kristofa.brave.httpclient.BraveHttpResponseInterceptor;
//import com.github.kristofa.brave.servlet.BraveServletFilter;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//
///**
// * @ClassName ZipkinConfig
// * @Description TODO
// * @Author wangBo
// * @Date 2019/6/23 0023 上午 10:58
// * @Version 1.0
// */
//@Configuration(value = "zipkinConfig")
//public class ZipkinConfig {
//
//    // zipkin 地址
//    private final String baseUrl = "http://master:9203";
//
//    // 连接超时时间
//    private final int connectTimeOut = 5000;
//
//    // 读取超时时间
//    private final int readTimeOut = 6000;
//
//    // 采集率
//    private final int traceSampler = 1;
//
//    // 指定serviceName
//    @Value("${spring.application.name:${vcap.application.name:${spring.config.name:application}}}")
//    private String serviceName;
//
//    /**
//     * 配置收集器
//     * @return
//     */
//    @Bean(name = "spanCollector")
//    public SpanCollector spanCollector() {
//        HttpSpanCollector.Config config = HttpSpanCollector.Config.builder().compressionEnabled(false).connectTimeout(connectTimeOut)
//                .flushInterval(1).readTimeout(readTimeOut).build();
//        return HttpSpanCollector.create(baseUrl, config, new EmptySpanCollectorMetricsHandler());
//    }
//
//    /**
//     *
//     * @param spanCollector
//     * @return
//     */
//    @Bean
//    public Brave brave(SpanCollector spanCollector) {
//        Builder builder = new Builder(serviceName);
//        builder.spanCollector(spanCollector);
//        builder.traceSampler(Sampler.create(traceSampler));// 采集率
//        return builder.build();
//    }
//
//    /**
//     * 拦截器，需要serverRequestInterceptor,serverResponseInterceptor 分别完成sr和ss操作
//     * @param brave
//     * @return
//     */
//    @Bean
//    public BraveServletFilter braveServletFilter(Brave brave) {
//        return new BraveServletFilter(brave.serverRequestInterceptor(), brave.serverResponseInterceptor(),
//                new DefaultSpanNameProvider());
//    }
//
//    /**
//     * httpClient客户端，需要clientRequestInterceptor,clientResponseInterceptor分别完成cs和cr操作
//     * @param brave
//     * @return
//     */
//    @Bean
//    public CloseableHttpClient httpClient(Brave brave) {
//        CloseableHttpClient httpclient = HttpClients.custom()
//                .addInterceptorFirst(new BraveHttpRequestInterceptor(brave.clientRequestInterceptor(),
//                        new DefaultSpanNameProvider()))
//                .addInterceptorFirst(new BraveHttpResponseInterceptor(brave.clientResponseInterceptor())).build();
//        return httpclient;
//    }
//}
